<?php
/**
 * 活动信息管理
 * @author Ice iceinto@mallog.com.cn
 */
class DisAction extends LoginAction
{
    /**
     * 默认活动列表
     * @author Ice iceinto@mallog.com.cn
     */
    public function index ()
    {
        $disModel = D('Discount');
        $dis = $disModel->getAllPor();
        $this->assign('page', $dis['page']);
        $this->assign('dis', $dis['data']);
        $this->display();
    }
    /**
     * 添加操作
     * @author Ice iceinto@mallog.com.cn
     */
    public function add ()
    {
        $this->getGetData();
        if (isPost()) {
            $data = $this->getPostData();
            $disModel = D('Discount');
            $status = $disModel->disUpdate($data);
            if ($status['status']) {
                $this->successMessage('操作成功！');
                $this->getGetData();
            } else {
                $this->errorMessage('操作失败！');
            }
        }
        $this->display();
    }
    /**
     * 获取和验证GET传参
     * @author Ice iceinto@mallog.com.cn
     */
    private function getGetData ()
    {
        //TODO 判断参数正确性
        $mId = intval(getGet('market'));
        $fId = intval(getGet('floor'));
        $bId = intval(getGet('brand'));
        $gId = intval(getGet('good'));
        $map = array();
        $map['mid'] = $mId;
        $this->setBaseData('Market', $map, 'market');
        //获取活动信息
        unset($map);
        $map['mid'] = $mId;
        $map['fid'] = $fId;
        $map['bid'] = $bId;
        $map['gid'] = $gId;
        $disModel = M('Discount');
        $dis = $disModel->where($map)->find();
        //设置变量
        $this->assign('mid', $mId);
        $this->assign('fid', $fId);
        $this->assign('bid', $bId);
        $this->assign('gid', $gId);
        $this->assign('dis', $dis);
    }
    /**
     * 获取POST参数
     * @author Ice iceinto@mallog.com.cn
     */
    private function getPostData ()
    {
        $data = array();
        $data['mid'] = intval(getPost('mid'));
        $fId = intval(getPost('fid'));
        $bId = intval(getPost('bid'));
        $gId = intval(getPost('gid'));
        if ($fId) {
            $data['fid'] = $fId;
            if ($bId) {
                $data['bid'] = $bId;
                if ($gId) {
                    $data['gid'] = $gId;
                }
            }
        }
        $data['intr'] = getPost('intr');
        $data['stime'] = getPost('stime');
        $data['etime'] = getPost('etime');
        //判断必要性
        foreach ($data as $k => $d) {
            if (! $d) {
                $this->error($k . '不能为空！');
            }
        }
        return $data;
    }
}
?>